package com.yuwenchao.superafflatus.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuwenchao.superafflatus.constant.AfflatusConstant;
import com.yuwenchao.superafflatus.pojo.entity.SuperBookfile;
import com.yuwenchao.superafflatus.pojo.entity.SuperShowColor;
import com.yuwenchao.superafflatus.service.SuperShowColorService;
import com.yuwenchao.superafflatus.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ChaooGG
 * @since 2021-05-31
 */
//@RestController
@Controller
//@RequestMapping("/superShowColor")
@Api(tags = "颜色详情展示")
@AllArgsConstructor
public class SuperShowColorController {


    //这里报错不建议Autowired 可根据构造器 配合private  final 注入
   /* @Autowired
    SuperShowColorService superShowColorService;*/


    //配合AllArgsConstructor注解 自动注入调用
    private  final SuperShowColorService superShowColorService;


    @ResponseBody
    @ApiOperation("颜色信息列表")
    @GetMapping("getSuperColorPageAjax")
    public R getSuperColorPage(String coloeName, Page page){

        IPage superColorPage = superShowColorService.getSuperColorPage(coloeName, page);

        return R.ok().data("superColorPage",superColorPage);
    }


    @PreAuthorize("hasRole('ROLE_normal')")
    @ApiOperation(value = "分页查询颜色展示")
    @GetMapping("toColorPage")
    public String getFilePageTxtBook(
            @RequestParam(value="condition",defaultValue="")String condition,
            @RequestParam(value="pn",defaultValue="1")Integer pn,
            Model model) {

        Page<SuperShowColor> pageColor = new Page<>(pn, AfflatusConstant.LIMIT_SIZE);
        //request.setAttribute("jumpUrl", "/index?&pn=");
        model.addAttribute("jumpUrl", "/toColorPage?pn=");
        QueryWrapper<SuperShowColor> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("chinese_desc",condition);
        final IPage<SuperShowColor> page = superShowColorService.page(pageColor, queryWrapper);

        List<SuperShowColor> list = pageColor.getRecords();//获取数据集合
        model.addAttribute("page",page);
        model.addAttribute("list",list);

        return "page/color/color";

    }

}

